import 'package:flutter/material.dart';

class EgOffstage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _EgOffstage();
  }
}

class _EgOffstage extends State<EgOffstage> {
  var isOffstage = false;

  void changeOffstage() {
    setState(() {
      isOffstage = !isOffstage;
      print("改变了显示");
    });
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text("控制是否显示组件"),
      ),
      body: new Center(
        child: new Offstage(
          offstage: isOffstage,
          child: Text("我在这里"),
        ),
      ),
      floatingActionButton: new FloatingActionButton(
        onPressed: changeOffstage,
        child: new Icon(Icons.flip),
      ),
    );
  }
}
